home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/usr/bin/perl ############################################################################## # Revved Search Version 1.0 # # Copyright 1998 Rev Ventures, Inc. info@revved.com # # Created 08/08/98 Last Modified 08/08/98 # # Software Archive at: http://www.revved.com # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1998 Rev Ventures, Inc. All Rights Reserved. # # # # Revved Search may be used and modified free of charge by anyone so long as # # this copyright notice and the comments above remain intact. By using this # # code you agree to indemnify Rev Ventures, Inc. from any liability that # # might arise from it's use. # # # # Selling this program's code without prior written consent is expressly # # forbidden. # # # # Obtain permission before redistributing this software over the Internet or # # in any other medium. In all cases copyright and header must remain intact.# ############################################################################## # Define core information: # $domain = "http://www.immortaldescendants.com"; $mainpath = "/usr/local/etc/httpd/htdocs/immortaldescendantscom"; @folders = ""; $exclusions = ""; ############################################################################## &ParseInput; print "Content-type: text/html\n\n"; if ($in{'keys'} && $in{'prc'}) { if ($in{'background'}) { $bg = "BACKGROUND=\"$in{'background'}\""; } print "<HTML><HEAD><TITLE>$in{'title'}</TITLE></HEAD>\n"; print "<BODY BGCOLOR=\"$in{'bgcolor'}\" $bg TEXT=\"$in{'textcolor'}\" LINK=\"$in{'linkcolor'}\" VLINK=\"$in{'vlinkcolor'}\"><CENTER>"; if ($in{'header'}) { @head = split(/,/, $in{'header'}); print "<IMG SRC=\"$head[0]\" WIDTH=\"$head[1]\" HEIGHT=\"$head[2]\"><P>\n"; } print "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=80\%><TR><TD>\n"; $a = 0; unless ($folders[0]) { $folders[0] = "$mainpath"; do { $first = shift (@folders); $paths[$a] = "$first"; $a++; opendir(ROOMDIR, "$first"); @hunts = sort(readdir(ROOMDIR)); closedir(ROOMDIR); foreach $hunt(@hunts) { $set = "$first/$hunt"; if ((-d "$set") && ($hunt ne ".") && ($hunt ne "..")) { unless ($exclusions =~ /\,$set\,/) { push (@folders, "$set"); } } } } until ($first eq ""); } $act = 0; $s = 0; $c = 0; unless ($in{'L'} && $in{'H'}) { $in{'L'} = 1; $in{'H'} = 10; } $verf = $in{'L'}; $nL = ($in{'H'} + 1); $nH = ($in{'H'} + 10); $pL = ($in{'L'} - 10); $pH = ($in{'H'} - 10); unless ($in{'prc'} eq "exact") { $in{'keys'} =~ s/\Wand\W/ /gi; $in{'keys'} =~ s/\Wor\W/ /gi; $in{'keys'} =~ s/\Wand\W/ /gi; $in{'keys'} =~ s/\Wor\W/ /gi; $in{'keys'} =~ s/\,/\, \,/gi; $in{'keys'} =~ s/\,//gi; $in{'keys'} =~ s/\+//gi; $in{'keys'} =~ s/ / /gi; if ($in{'keys'} =~ / /) { @keys = split(/ /,$in{'keys'}); } else { $keys[0] = $in{'keys'}; } foreach $key(@keys) { if ($key) { $act++; } } if ($in{'keys'} eq "") { print "<B>The search you are attempting is too vague. Please try again.</B></TD></TR></TABLE>"; exit; } } foreach $path(@paths) { $relpath = $path; $relpath =~ s/$mainpath\///gi; $relpath =~ s/$mainpath//gi; opendir(ROOMDIR, "$path"); @files = sort(readdir(ROOMDIR)); closedir(ROOMDIR); foreach $file(@files) { if (-T "$path/$file") { open (DOC, "$path/$file"); $add = "no"; $inibuff = ""; $finbuff = ""; do { $line = <DOC>; $inibuff .= $line; } until ($line eq ""); close (DOC); $inibuff =~ s/\n/ /i; $inibuff =~ s/\ \;//gi; if (($inibuff =~ /<TITLE>/i) && ($inibuff =~ /<\/TITLE>/i)) { @step1 = split(/<TITLE>/i, $inibuff); @step2 = split(/<\/TITLE>/i, $step1[1]); $header = $step2[0]; $inibuff =~ s/<TITLE>.*\<\/TITLE>//i; } @fltr1 = split(/</, $inibuff); $inibuff = ""; foreach $lcarr(@fltr1) { if ($lcarr =~ />/) { @fltr2 = split(/>/, $lcarr); $inibuff .= $fltr2[1]; } else { $inibuff .= $lcarr; } } if ($in{'prc'} eq "any") { $comp = 0; foreach $key(@keys) { if ($key) { if (($inibuff =~ /\W$key\W/i) || ($header =~ /\W$key\W/i)) { $comp++; } } } if ($comp > 0) { $add = "yes"; $ttl++; } } if ($in{'prc'} eq "all") { $comp = 0; foreach $key(@keys) { if ($key) { if (($inibuff =~ /\W$key\W/i) || ($header =~ /\W$key\W/i)) { $comp++; } } } if ($comp >= $act) { $add = "yes"; $ttl++; } } if ($in{'prc'} eq "exact") { if ($inibuff =~ /\W$in{'keys'}\W/i) { $add = "yes"; $ttl++; } } if ($add eq "yes") { $s++; } if (($add eq "yes") && ($s >= $in{'L'})) { unless ($s > $in{'H'}) { @fltr1 = split(/ /, $inibuff); $inibuff = ""; $i = 0; $stp = @fltr1; do { $inibuff .= " $fltr1[$i]"; $lgth = length($inibuff); $i++; } until (($lgth >= 200) || ($i > $stp)); if ($relpath) { $fs = "\/"; } else { $fs = ""; } if ($header) { $result[$c] = "<A HREF=\"\/$relpath$fs$file\">$header</A><BR><FONT SIZE=2>$inibuff . . .\n</FONT><P>\n"; } else { $result[$c] = "<A HREF=\"\/$relpath$fs$file\">$domain\/$file</A><BR><FONT SIZE=2>$inibuff . . .\n</FONT><P>\n"; } $verf++; $c++; } } } } } --$verf; splice (@result, 10, 1); if ($verf <= 0) { print "<B><FONT SIZE=4>Sorry. No pages matched your search.<BR><BR>"; &PrintForm; exit; } if ($in{'L'} == $verf) { print "<FONT SIZE=4><B>Search Results:</FONT></B><BR>Match $verf</B><HR><BR>"; } else { print "<FONT SIZE=4><B>Search Results:</FONT></B><BR>Matches $in{'L'} \- $verf out of $ttl</B><HR><BR>"; } foreach $match(@result) { print "$match"; } print "<HR><CENTER><TABLE CELLPADDING=4 CELLSPACING=0 BORDER=0><TR>"; unless ($in{'H'} < 11) { print "<TD><FORM METHOD=\"post\" ACTION=\"search.cgi\"><INPUT TYPE=\"hidden\" NAME=\"keys\" VALUE=\"$in{'keys'}\"><INPUT TYPE=\"hidden\" NAME=\"L\" VALUE=\"$pL\"><INPUT TYPE=\"hidden\" NAME=\"H\" VALUE=\"$pH\"><INPUT TYPE=\"hidden\" NAME=\"prc\" VALUE=\"$in{'prc'}\"><INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"$in{'title'}\"><INPUT TYPE=\"hidden\" NAME=\"header\" VALUE=\"$in{'header'}\"><INPUT TYPE=\"hidden\" NAME=\"bgcolor\" VALUE=\"$in{'bgcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"background\" VALUE=\"$in{'background'}\"><INPUT TYPE=\"hidden\" NAME=\"textcolor\" VALUE=\"$in{'textcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"linkcolor\" VALUE=\"$in{'linkcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"vlinkcolor\" VALUE=\"$in{'vlinkcolor'}\"><INPUT TYPE=\"submit\" VALUE=\"Previous Matches\"></FORM></TD>"; } unless ($ttl == $verf) { print "<TD><FORM METHOD=\"post\" ACTION=\"search.cgi\"><INPUT TYPE=\"hidden\" NAME=\"keys\" VALUE=\"$in{'keys'}\"><INPUT TYPE=\"hidden\" NAME=\"L\" VALUE=\"$nL\"><INPUT TYPE=\"hidden\" NAME=\"H\" VALUE=\"$nH\"><INPUT TYPE=\"hidden\" NAME=\"prc\" VALUE=\"$in{'prc'}\"><INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"$in{'title'}\"><INPUT TYPE=\"hidden\" NAME=\"header\" VALUE=\"$in{'header'}\"><INPUT TYPE=\"hidden\" NAME=\"bgcolor\" VALUE=\"$in{'bgcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"background\" VALUE=\"$in{'background'}\"><INPUT TYPE=\"hidden\" NAME=\"textcolor\" VALUE=\"$in{'textcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"linkcolor\" VALUE=\"$in{'linkcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"vlinkcolor\" VALUE=\"$in{'vlinkcolor'}\"><INPUT TYPE=\"submit\" VALUE=\"More Matches\"></FORM></TD>"; } print "</TR></TABLE><HR>"; &PrintForm; } else { print "<HTML><HEAD><TITLE>Error in search attempt</TITLE></HEAD><BODY BGCOLOR=\"FFFFFF\"><BR><BR><BLOCKQUOTE><FONT SIZE=4><B>ERROR:</B></FONT> You have not entered any search criteria. Please press <B>BACK</B> on your browser and try again.</BODY>\n</HTML>"; } sub ParseInput { if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { &error('request_method'); } foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<!--(.|\n)*-->//g; if ($name && $value) { $in{$name} = $value; } } } sub PrintForm { print "<BR></CENTER><FORM METHOD=\"post\" ACTION=\"search.cgi\"> <TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0><TR><TD COLSPAN=3><B><FONT SIZE=4>Search again:</FONT></B></TD></TR><TR><TD>search for:</TD><TD><INPUT TYPE=\"text\" NAME=\"keys\" SIZE=20></TD><TD><INPUT TYPE=\"submit\" VALUE=\"Search\"></TD></TR><TR><TD ALIGN=\"right\">match:</TD><TD COLSPAN=2><SELECT NAME=\"prc\" SIZE=1> <OPTION SELECTED VALUE=\"any\">any of the words <OPTION VALUE=\"all\">all of the words <OPTION VALUE=\"exact\">the exact phrase </SELECT></TD></TR></TABLE> <INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"$in{'title'}\"> <INPUT TYPE=\"hidden\" NAME=\"header\" VALUE=\"$in{'header'}\"> <INPUT TYPE=\"hidden\" NAME=\"bgcolor\" VALUE=\"$in{'bgcolor'}\"> <INPUT TYPE=\"hidden\" NAME=\"background\" VALUE=\"$in{'background'}\"> <INPUT TYPE=\"hidden\" NAME=\"textcolor\" VALUE=\"$in{'textcolor'}\"> <INPUT TYPE=\"hidden\" NAME=\"linkcolor\" VALUE=\"$in{'linkcolor'}\"> <INPUT TYPE=\"hidden\" NAME=\"vlinkcolor\" VALUE=\"$in{'vlinkcolor'}\"> </FORM></TD></TR></TABLE>\n</BODY>\n</HTML>"; }